/**
 * Created by bo.wang on 2022/3/1.
 */
import React from 'react'
import {Label, Tag, Text} from "react-konva"
import KonvaTypes from "konva"

interface LabelRectProps extends KonvaTypes.NodeConfig {
    text?: string
    color?: string
    onClick?: (layer: KonvaTypes.Container | null) => void
    onDblClick?: (layer?: KonvaTypes.Container | null) => void
    selected?: boolean
}


const LabelRect = (props: LabelRectProps) => {
    return (
        <Label
            id={props.id}
            name={props.name}
            draggable={props.draggable}
            x={props.x}
            y={props.y}
            onDblClick={(e) => props.onDblClick ? props.onDblClick(e.target.parent) : null}
            onClick={(e) => props.onClick ? props.onClick(e.target.parent) : null}
        >
            <Tag
                fill={props.fill || "#787785"}
                opacity={props.selected ? 1 : 0.8}
                shadowBlur={10}
                shadowColor={props.fill || "#787785"}
                shadowOpacity={props.selected ? 1 : 0.5}
                cornerRadius={4}

            />
            <Text
                padding={10}
                fill={props.color || "white"}
                text={props.text}
                fontSize={15}
                fontFamily={"Microsoft YaHei UI, serif"}
            />
        </Label>
    )
}

export default LabelRect